package com.jingdianjichi.subject.domin.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.concurrent.*;

/**
 * 线程池的config
 * @author 86156
 * @version 1.0
 * @date 2024-11-09 16:04
 */
@Configuration
public class ThreadPoolConfig {

    @Bean(name = "labelThreadPool")
    public ThreadPoolExecutor getLabelThreadPool(){
        return new ThreadPoolExecutor(
                10,
                100,
                5,
                TimeUnit.SECONDS,
                new LinkedBlockingDeque<>(40),
                new CustomNameThreadFactory("label"),
                new ThreadPoolExecutor.CallerRunsPolicy()
        );
    }
}

/**
 * 多线程的四种拒绝策略
 * AbortPolicy 直接拒绝,并抛出异常,不友好
 * CallerRunsPolicy 将任务退回给调用者线程,友好
 * DiscardPolicy 直接丢弃,适用于对任务丢失不敏感的情况
 * DiscardOldestPolicy 丢弃最旧的一个等待任务,不友好
 */
